﻿using System;

public class MD5
{
	public static string Create(string str)
	{
		return Create(str, 7);
	}
	public static string Create(string str, int tag)
	{
		string full = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");
		string flag = dec2bin(tag, 4), rtv = "";
		if (flag.Substring(0, 1) == "1") rtv += full.Substring(0, 8);
		if (flag.Substring(1, 1) == "1") rtv += full.Substring(8, 8);
		if (flag.Substring(2, 1) == "1") rtv += full.Substring(16, 8);
		if (flag.Substring(3, 1) == "1") rtv += full.Substring(24, 8);
		return rtv;
	}
	private static string dec2bin(int dec, int length)
	{
		string numstr = "";
		while (dec > 0)
		{
			numstr = Convert.ToString(dec % 2) + numstr;
			dec = Convert.ToInt32(dec / 2);
		}
		return numstr.PadLeft(length, '0');
	}
}